package com.buka.goods.mapper;

import com.buka.server.pojo.ProductDetails;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

@org.apache.ibatis.annotations.Mapper
public interface ProductDetailsMapper extends Mapper<ProductDetails> {
    @Update("update ProductDetails set num=num-#{num} where product_id=#{productId} and num>=#{num}")
    int reducedInventory(@Param("productId") Long productId,
                         @Param("num") Integer num
    );

    @Update("update ProductDetails set num=num+#{num} where product_id=#{productId}")
    int addInventory(@Param("productId") Long productId,
                     @Param("num") Integer num
    );
}